//
//  AppDelegate.m
//  FullHouse
//
//  Created by dllo on 16/1/15.
//  Copyright © 2016年 yy. All rights reserved.
//

#import "AppDelegate.h"
#import "AllBarsHeader.h"
#import "MZY_GuidePageController.h"

@interface AppDelegate ()<UITabBarControllerDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
    
    MZY_BrowseViewController *browseVC = [[MZY_BrowseViewController alloc]init];
    UINavigationController *browseNAVC = [[UINavigationController alloc] initWithRootViewController:browseVC];
    browseNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"浏览" image:[UIImage imageNamed:@"browse.png"] tag:1001];
    
    MZY_InspirationViewController *insVC = [[MZY_InspirationViewController alloc]init];
    UINavigationController *insNAVC = [[UINavigationController alloc] initWithRootViewController:insVC];
    insNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"灵感" image:[UIImage imageNamed:@"inspiration.png"] tag:1002];
    
    MZY_CommunityViewController *comVC = [[MZY_CommunityViewController alloc]init];
    UINavigationController *comNAVC = [[UINavigationController alloc] initWithRootViewController:comVC];
    comNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"社区" image:[UIImage imageNamed:@"community.png"] tag:1003];
    
    MZY_ExpertViewController *expVC = [[MZY_ExpertViewController alloc]init];
    UINavigationController *expNAVC = [[UINavigationController alloc] initWithRootViewController:expVC];
    expNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"专家" image:[UIImage imageNamed:@"expert.png"] tag:1004];
    
    MZY_SelfViewController *selfVC = [[MZY_SelfViewController alloc]init];
    UINavigationController *selfNAVC = [[UINavigationController alloc] initWithRootViewController:selfVC];
    selfNAVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我" image:[UIImage imageNamed:@"self.png"] tag:1005];
    
    //判断是不是第一次启动
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
        NSLog(@"第一次启动");
        // 如果是第一次启动,使用引导页作为根视图
        MZY_GuidePageController *useVC = [[MZY_GuidePageController alloc]init];
        self.window.rootViewController = useVC;
    }else{
        NSLog(@"不是第一次启动");
        // 如果不是第一次启动,使用"tabbar"作为根视图
        // 设置根视图控制器
        UITabBarController *tabVC = [[UITabBarController alloc]init];
        self.window.rootViewController = tabVC;
        
        // 管理"vc"
        tabVC.viewControllers = @[browseNAVC,insNAVC,comNAVC,expNAVC,selfNAVC];
        // 取消半透明效果
        tabVC.tabBar.translucent = NO;
        // 设置"tabbar"颜色
        tabVC.tabBar.tintColor = [UIColor whiteColor];
        // 点击图标颜色
        tabVC.tabBar.tintColor = [UIColor orangeColor];
        // 设置代理人
        tabVC.delegate = self;
        
    }
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [self.window release];
    
    return YES;
}

// "tabbar"的点击方法
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    viewController.tabBarItem.badgeValue = nil;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
